package utils

import (
	"log"
	"os"
)

var logger *log.Logger

func WriteLog() *log.Logger {
	return logger
}

func init() {
	if _, err := os.Stat("logs"); os.IsNotExist(err) {
		err := os.MkdirAll("logs", 0755)
		if err != nil {
			log.Panic("logs 目录创建失败")
		}
	}
	logFile, err := os.OpenFile("logs/pipline_tag.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
	if err != nil {
		log.Panic("打开日志文件异常")
	}

	logger = log.New(logFile, "[pipline_build_tag]", log.Ldate|log.Ltime|log.Lshortfile)
}
